#pragma once
#include "QD3DUtils.h"
#include "QD3DContext.h"
#include <Qwidget>

class QD3DWidget : public QWidget
{
	Q_OBJECT

public:
	QD3DWidget (QWidget* parent = 0, QSize size = QSize (800, 600));
	virtual ~QD3DWidget ();

	QPaintEngine* paintEngine () const;
	bool initialized () const;
	QD3DContext *getD3DContextPtr ();
	const QD3DContext *getD3DContextPtr () const;

	void swapBuffers ();

protected:

	virtual void initializeD3D () {}
	virtual void paintD3D () {}
	virtual void resizeD3D (int width, int height) {}

	virtual void paintEvent (QPaintEvent *e);
	virtual void resizeEvent (QResizeEvent *e);

	void setAutoBufferSwap (bool isAuto);

private:

	QD3DContext *_pContext;
	bool _isAuto;

	void _d3DInit ();
	void _d3DDraw ();

	virtual void closeEvent (QCloseEvent *e);

};
